package jpb.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

/**
 * Created by haol on 2017/7/22.
 */
public class XmlUtil {

        private Logger logger = LoggerFactory.getLogger(XmlUtil.class);

        public static String getStrByNode (String node){

                String doc = "/home/file/phone/config.xml";
                String doc1 = "src/main/resource/config.xml";
               // doc ="C:\\config.xml";

                File file = new File(doc);

                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance() ;
                try {
                        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
                        Document document = documentBuilder.parse(file);
                        NodeList nodeList = document.getElementsByTagName(node);
                        Node classNode = nodeList.item(0).getFirstChild();
                        String value = classNode.getNodeValue();
                        return value;
                }catch (Exception e){
                        return "no";
                }
        }
}
